package logic

import (
	"context"
	"lucky_srv/lucky"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SearchGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSearchGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchGoodsLogic {
	return &SearchGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SearchGoodsLogic) SearchGoods(req *types.SearchGoodsRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	goods, err := l.svcCtx.LuckySrv.SearchGoods(l.ctx, &lucky.SearchGoodsRequest{
		Title:     req.Title,
		Taste:     req.Taste,
		MinPrice:  req.MinPrice,
		MaxPrice:  req.MaxPrice,
		SortWord:  req.SortWord,
		OrderType: req.OrderType,
		Page:      req.Page,
		PageSize:  req.PageSize,
	})

	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "饮品检索成功",
		Code:    500,
		Data:    goods,
	}, nil
}
